package com.rpg.visao;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;

public class Principal extends JFrame implements ActionListener {

	private JPanel principalPanel;
	JLabel label = new JLabel();
	private JPanel buttonPanel;
	static Janela janela = null;

	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Principal frame1 = new Principal();
					frame1.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	public ImageIcon getImage(String url) {
		Image img = null;
		try {
			img = ImageIO.read(getClass().getResource(url));
		} catch (IOException e) {
			e.getMessage();
		}
		ImageIcon im = new ImageIcon(img);
		return im;
	}

	public Principal() {
		setTitle("Launcher RPG");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 250, 300);
		setResizable(false);

		principalPanel = new JPanel();
		principalPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		principalPanel.setLayout(new BorderLayout(0, 0));
		setContentPane(principalPanel);

		JPanel panel = new JPanel();
		principalPanel.add(panel, BorderLayout.NORTH);
		ImageIcon img = getImage("resources/logoxd.png");
		label.setHorizontalAlignment(SwingConstants.CENTER);
		label.setIcon(img);
		panel.add(label);

		buttonPanel = new JPanel();
		principalPanel.add(buttonPanel, BorderLayout.SOUTH);

		JButton buttonCriarManual = new JButton("Criar Equipe Manualmente");
		buttonCriarManual.addActionListener(this);

		JButton buttonCriarAleatorio = new JButton(
				"Criar Equipe Aleat�riamente");

		JButton buttonSair = new JButton("Sair do Jogo");

		buttonPanel.setLayout(new GridLayout(3, 1));

		buttonPanel.add(buttonCriarManual);
		buttonPanel.add(buttonCriarAleatorio);
		buttonPanel.add(buttonSair);

	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
		String x = arg0.getActionCommand();
		switch (x) {
		case "Criar Equipe Manualmente":
			this.setVisible(false);
			janela = new Janela();
			trocar(new CharSelectPanel());
		}
	}


	public static void trocar(JPanel panel) {
		janela.trocarPanel(panel);

	}

}
